import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedSize;

    public MyStack() {
        this.elem = new int[5];
    }

    //压栈
    public void push(int val) {
        if(isFull()) {
           elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize] = val;
        usedSize++;
    }

    public boolean isFull() {
        return usedSize == elem.length;
    }


    //出栈
    public int pop() {
        //1、判断栈不为空
        if(empty()) {
            //抛出异常！！
            throw new StackEmptyException("栈为空！");
        }
        //2、开始删除
        return elem[--usedSize];
    }

    //获取栈顶元素
    public int peek() {
        //1、判断栈不为空
        if(empty()) {
            //抛出异常！！
            throw new StackEmptyException("栈为空！");
        }
        //2、开始删除
        return elem[usedSize-1];
    }

    public boolean empty() {
        return usedSize == 0;
    }
}
